<?php
/**
*自定义的验证类
**/
namespace Fang\UserBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
//需要使用到服务
use Symfony\Component\DependencyInjection\ContainerInterface as Container;

class UserUniqueValidator extends ConstraintValidator
{
	private $container;

	public function __construct(Container $container)
	{
		$this->container = $container;	
	}
	/**
	*执行的验证函数
	*@params $value 验证的数据
	*@params $constraint 调用当前验证类的约束类
	**/
	public function validate($value, Constraint $constraint)
	{
		$doctrine = $this->container->get("doctrine");
		if($value=="123123")
		{
			$this->context->buildViolation($constraint->message)->setParameter('%string%', $value)->addViolation();
		}
	}
}
